package Z11_11_atomic;

import java.util.concurrent.atomic.AtomicStampedReference;

/**
 * @author： pang-yun
 * @date： 2021-11-11 15:06
 * 功能目的 ：用于  加了版本号 的 原子引用
 */

public class AtomicStampedReferenceDemo {
    public static void main(String[] args) {
        Dog b = new Dog("b", 2);
        AtomicStampedReference<Dog> stampedReference = new AtomicStampedReference<Dog>(b,1);
        // 获取值
        System.out.println(stampedReference.getReference());
        //  获取版本号
        System.out.println(stampedReference.getStamp());

        stampedReference.compareAndSet(b,new Dog("c",99),stampedReference.getStamp(),stampedReference.getStamp()+3);

        System.out.println(stampedReference.getReference());
        System.out.println(stampedReference.getStamp());


    }
}
